import { _decorator, Component, Node, Sprite, Enum } from 'cc';
import { CtrlModeListener } from '../../core/GameInputListeners';
import { InputKeyCode } from '../../core/InputConfig';
import GameInputMgr from '../../core/GameInputMgr';
const { ccclass, property } = _decorator;

@ccclass('KeyTipHandler')
export class KeyTipHandler extends Component implements CtrlModeListener {
    @property({ type: Enum(InputKeyCode) })
    keyCode: InputKeyCode = InputKeyCode.NONE;

    @property(Sprite)
    tip: Sprite = null;

    private _group: number = 0;//按键策略组

    onChangeMode(mode: string): void {
        this.setKeyTipSprite()
    }

    private setKeyTipSprite() {
        if (this.tip) {
            this.tip.node.active = true;
            let keyName = GameInputMgr.instance().getKeyCodeImgByKeyValue(this.keyCode, this._group);
            //TODO
            // this.tip.spriteFrame = UIManager.getInstance().getKeyTip(keyName);
        }
    }
    start() {
        this.setKeyTipSprite()
        this._group = GameInputMgr.instance().converter.getGroup();
        GameInputMgr.instance().addCtrlModeListener(this)
    }

    onDestroy() {
        GameInputMgr.instance().removeCtrlModeListener(this)
    }

    update(deltaTime: number) {

    }
}

